package com.example.yls.demoa;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements IOnTimeChangeListener {
    private Button bt1;
    private TextView showView;
    private MyReceiver receiver;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e("MyService","thread id ="+Thread.currentThread().getId());

        receiver = new MyReceiver(MainActivity.this);
        IntentFilter filter =new IntentFilter();
        filter.addAction("TIME_CHANGE");
        registerReceiver(receiver,filter);
        bt1=findViewById(R.id.fuwu);
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,MyService.class);
                startService(intent);
            }
        });
        showView=findViewById(R.id.txt);

    }

    @Override
    public void show(String str) {
        showView.setText(str);
    }
}
